<?php
session_start();
set_error_handler('exceptions_error_handler');

function exceptions_error_handler($severity, $message, $filename, $lineno) {
  if (error_reporting() == 0) {
    return;
  }
  if (error_reporting() & $severity) {
    throw new ErrorException($message, 0, $severity, $filename, $lineno);
  }
}

/**
 * Automatisches Laden der angeforderten Klasse
 */
function __autoload($className)
{
	$knownFolders = array("./fw/", "./Controller/", "./Models/");
	$classFile = "";
	$foundClass = false;
	
	if (substr($className, 0, 4) == "DAO_")
	{
		$classFile = "./Models/" . substr($className, 4, strlen($className) - 4) . ".DAO.php";
		if (file_exists($classFile))
		{
			$foundClass = true;
			include($classFile);
		}
	}
	else
	{	
		foreach ($knownFolders as $folder)
		{
			$classFile = $folder . $className . ".class.php";
			if (file_exists($classFile))
			{
				$foundClass = true;
				include($classFile);
				break;
			}
		}
	}
	
	if (!$foundClass)
		throw new Exception("Klasse " . $className . " wurde nicht gefunden.");
}

?>